package pers.mor.tomcat.config;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import pers.mor.tomcat.http.Constant;

public class ContextXML {

    private static String webInf = null;

    private static Element getRootElement() {
        Document doc = null;
        try {
            doc = new SAXReader().read(Constant.contextXmlFile);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return doc.getRootElement();
    }

    public static void initWebInf() {
        Element root = getRootElement();
        String value = root.elementText("WatchedResource");
        webInf =  value == null || value.equals("") ? "WEB-INF/web.xml" : value;
    }

    public static String getWebInf() {
        return webInf;
    }
}
